package com.example.shushiyunsst.fragment.main.home.child.miner.sub

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.example.library_common.base.BaseFragmentEx
import com.example.library_common.global.AppGlobals
import com.example.shushiyunsst.R
import com.example.shushiyunsst.widget.lab_layout.JssFixTabLayout

/**
 * 星树交易
 * */
class StartTransferFragment:BaseFragmentEx() {

    companion object{
        fun newInstance(): StartTransferFragment {
            val args = Bundle()

            val fragment = StartTransferFragment()
            fragment.arguments = args
            return fragment
        }
    }

    private lateinit var mTabLayout: JssFixTabLayout

    private lateinit var mViewPager: ViewPager

    private val subPages= arrayOf<BaseFragmentEx>(
        StartTransferBuyingFragment.newInstance(),
        StartTransferSellFragment.newInstance()
    )

    override fun getLayoutId()= R.layout.start_franstfer_fragment

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.findViewById<View>(R.id.headerLayout)
            .setBackgroundColor(Color.TRANSPARENT)

        val mToolbar:Toolbar=view.findViewById(R.id.mToolbar)

        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }

        mTabLayout=view.findViewById(R.id.mTabLayout)
        mViewPager=view.findViewById(R.id.mViewPager)

        mViewPager.adapter=object
            :FragmentStatePagerAdapter(childFragmentManager,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT){
            override fun getCount()=subPages.size

            override fun getItem(position: Int)=subPages[position]

            override fun getPageTitle(position: Int): CharSequence? {
                val lab = getItem(position) as StartTransferLab
                return  AppGlobals.getApplication().getString(lab.title)
            }
        }

        mTabLayout.setViewPager(mViewPager)
        mTabLayout.notifyDataSetChanged()
    }

    override fun onBackPressedSupport(): Boolean {
        pop()
        return true
    }

}